#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<wait.h>

int main()
{
    pid_t id = fork();
    if(id < 0)
    {
        perror("fork");
        exit(1);
    }
    else if (id == 0)
    {
        //子进程
        int cnt = 3;
        while(cnt)
        {
            printf("我是子进程pid: %d ppid: %d\n",getpid(),getppid());
            sleep(1);
        }
        exit(11);
    }
    else{
        //父进程
        sleep(5);
        int status = 0;
        pid_t ret = waitpid(id, &status, 0);
        printf("返回值：%d  子进程退出码: %d  终止信号：%d\n",ret, (status >> 8) & 0xFF, status & 0x7F);
        sleep(2);
//        while(1)
//        {
//            printf("我是父进程pid: %d ppid: %d\n",getpid(),getppid());
//            sleep(1);
//        }
    }
    return 0;
}
